﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="frmCompras.aspx.cs" Inherits="Box.Cliente.Logistica.Compras.frmCompras" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">

    <div class="col-lg-12">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <h3>Información de la Compra</h3>
            </div>
            <div class="panel-body">
                <div class="col-lg-12">
                    <asp:HiddenField ID="hfIdCompra" runat="server" />

                    <div class="row">
                        <asp:UpdatePanel ID="upCliente" runat="server">
                            <ContentTemplate>

                                <div class="row">
                                    <div class="col-md-4 .col-md-push-3">
                                        <div class="panel-body">
                                            <tr>
                                                <td>
                                                    <h5><strong>RUC/DNI</strong></h5>
                                                </td>
                                                <td>
                                                    <div class="input-group">
                                                        <asp:TextBox ID="txtRuc" class="form-control" MaxLength="11" runat="server" />
                                                       <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender6" TargetControlID="txtRuc" FilterType="Numbers" runat="server"></ajaxToolkit:FilteredTextBoxExtender>

                                                        <span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>

                                                    </div>
                                                    <asp:Button runat="server" class="glyphicon glyphicon-remove label label-danger" ID="btnBuscarProveedor" Text="Buscar"
                                                        OnClick="btnBuscarProveedor_Click" Width="100" />
                                                </td>

                                                <td>
                                                    <h5><strong>Proveedor</strong></h5>
                                                </td>
                                                <td>
                                                    <asp:TextBox CssClass="form-control input-sm" Enabled="False" ID="txtCliente" runat="server" />

                                                </td>
                                                <td>
                                                    <h5><strong>Dirección</strong></h5>
                                                </td>
                                                <td>
                                                    <asp:TextBox CssClass="form-control input-sm" Enabled="False" ID="txtDireccion" runat="server" />
                                                </td>

                                                <td>
                                                    <h4><strong>TOTAL</strong></h4>
                                                </td>
                                                <td>
                                                    <h4><strong>
                                                        <asp:Label ID="lblTotal1" Text="0.0" runat="server" /></strong></h4>
                                                </td>

                                            </tr>

                                        </div>
                                    </div>
                                    <div class="col-md-4 .col-md-push-3">
                                        <div class="panel-body">

                                            <tr>
                                                <td>
                                                    <h5><strong>Estado</strong></h5>
                                                </td>
                                                <td>
                                                    <asp:DropDownList
                                                        CssClass="form-control input-sm"
                                                        ID="ddlEstado"
                                                        runat="server"
                                                        Width="250">
                                                        <asp:ListItem>En Proforma</asp:ListItem>
                                                        <asp:ListItem>En orden de Compra</asp:ListItem>
                                                        <asp:ListItem>Atendido</asp:ListItem>
                                                        <asp:ListItem>Mal estado</asp:ListItem>
                                                    </asp:DropDownList>
                                                </td>

                                                <td>
                                                    <h5><strong>Adjuntar</strong></h5>
                                                </td>
                                                <td>
                                                    <asp:FileUpload ID="fuArchivo" CssClass="form-control input-sm" runat="server" />
                                                </td>

                                                <td>
                                                    <h5><strong>Número de documento</strong></h5>
                                                </td>
                                                <td>
                                                    <asp:TextBox ID="txtCodigo" CssClass="form-control input-sm" MaxLength="8" runat="server" />
                                                     <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender3" TargetControlID="txtCodigo" FilterType="Numbers, Custom" ValidChars="-,/" runat="server"></ajaxToolkit:FilteredTextBoxExtender>

                                                </td>

                                            </tr>
                                        </div>
                                    </div>
                                    <div class="col-md-4 .col-md-push-3">
                                        <div class="panel-body">

                                            <tr>

                                                <td>
                                                    <h5><strong>Tipo de documento</strong></h5>

                                                </td>
                                                <td>
                                                    <asp:DropDownList
                                                        CssClass="form-control input-sm"
                                                        ID="ddlDocumento"
                                                        ItemType="Box.Entities.TipoDocumento"
                                                        DataTextField="NombreTipoDocumento"
                                                        DataValueField="Id"
                                                        runat="server"
                                                        SelectMethod="GetTipoDocumentos" />
                                                </td>

                                                <td>
                                                    <h5><strong>Fecha de Compra</strong></h5>
                                                </td>
                                                <td>
                                                    <asp:TextBox CssClass="form-control input-sm" data-format="dd/MM/yyyy hh:mm:ss" MaxLength="10" ID="txtFecha" runat="server" />
                                                 <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender2" TargetControlID="txtFecha" FilterType="Numbers, Custom" ValidChars="/" runat="server"></ajaxToolkit:FilteredTextBoxExtender>
                                                                                        <ajaxToolkit:CalendarExtender ID="aceFechInicio"
                                        runat="server" Enabled="True" TargetControlID="txtFecha"
                                        Format="dd/MM/yyyy" TodaysDateFormat="dd/MM/yyyy">
                                    </ajaxToolkit:CalendarExtender>

                                                </td>
                                                <td>
                                                    <h5><strong>Tipo de Pago</strong></h5>

                                                </td>
                                                <td>
                                                    <asp:DropDownList ID="ddlTipoPago" CssClass="form-control input-sm" runat="server">
                                                        <asp:ListItem Text="Al contado" Value="Al contado" />
                                                        <asp:ListItem data-toggle="modal" data-target="#myModal" Text="A credito" Value="A credito" />
                                                    </asp:DropDownList>
                                                </td>
                                            </tr>

                                        </div>
                                    </div>

                                </div>

                            </ContentTemplate>
                            <Triggers>
                                <asp:AsyncPostBackTrigger ControlID="btnBuscarProveedor" EventName="Click" />
                            </Triggers>
                        </asp:UpdatePanel>
                    </div>

                    <div class="row">
                        <div class="col-md-6 .col-md-push-3">
                            <div class="panel panel-primary">
                                <div class="panel-heading">
                                    <h3>Productos</h3>
                                </div>
                                <div class="panel-body">

                                    <table>
                                        <tr>
                                            <td class="auto-style8">
                                                <asp:TextBox ID="txtCriterio" CssClass="form-control input-sm" placeholder="BUSCAR INSUMO/PRODUCTO" runat="server" Width="500px" /></td>
                                            <td class="auto-style4">
                                                <asp:Button runat="server" CssClass="btn btn-default input-sm" Text="Buscar" ID="btnBuscar" Height="31px" Width="106px" /></td>
                                        </tr>
                                    </table>

                                    <asp:UpdatePanel runat="server" ID="upInsumos">
                                        <ContentTemplate>
                                            <asp:ListView ID="lvInsumos"
                                                ItemType="Box.Entities.Insumo"
                                                SelectMethod="GetInsumos"
                                                runat="server"
                                                OnItemCommand="lvInsumos_ItemCommand">
                                                <EmptyDataTemplate>
                                                    <b>No se han encontrado Insumos..!!</b>
                                                </EmptyDataTemplate>
                                                <LayoutTemplate>
                                                    <table class="table table-hover table-condensed">
                                                        <thead>
                                                            <tr>

                                                                <th>Descripción</th>
                                                                <th>Precio</th>
                                                                <th>Und. Medida</th>
                                                                <th>Acciones</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                            <tr id="itemPlaceholder" runat="server" />
                                                        </tbody>
                                                    </table>
                                                    <asp:DataPager ID="dpProductos" PagedControlID="lvInsumos" runat="server" PageSize="5">
                                                        <Fields>
                                                            <asp:NextPreviousPagerField
                                                                ButtonType="Link"
                                                                ShowFirstPageButton="True"
                                                                ShowLastPageButton="True"
                                                                ShowNextPageButton="True"
                                                                ShowPreviousPageButton="True" />
                                                        </Fields>
                                                    </asp:DataPager>
                                                </LayoutTemplate>
                                                <ItemTemplate>
                                                    <tr>
                                                        <th><%# Item.NombreInsumo +" "+ Item.DescripcionInsumo %></th>
                                                        <th><%# Item.Precio %></th>
                                                        <th><%# Item.MedidaInsumo %></th>
                                                        <th>
                                                            <asp:Button ID="btnAgregar"
                                                                Text="Agregar" CommandName="AddDetalle"
                                                                CommandArgument="<%# Item.Id %>"
                                                                CssClass="btn btn-info btn-sm" runat="server" />
                                                        </th>
                                                    </tr>
                                                </ItemTemplate>
                                            </asp:ListView>
                                        </ContentTemplate>
                                        <Triggers>
                                            <asp:AsyncPostBackTrigger ControlID="btnBuscar" EventName="Click" />
                                        </Triggers>
                                    </asp:UpdatePanel>
                                </div>
                            </div>

                        </div>
                        <div class="col-md-6 .col-md-push-4">

                            <div class="panel panel-primary">
                                <div class="panel-heading">
                                    <h3>Detalle de la Compra</h3>
                                </div>
                                <div class="panel-body"></div>
                                <asp:UpdatePanel runat="server" ID="upDetalle">
                                    <ContentTemplate>
                                        <asp:ListView ID="lvDetCompra" runat="server" OnItemCommand="lvDetCompra_ItemCommand">
                                            <EmptyDataTemplate>
                                                <table class="table table-hover table-condensed">
                                                    <thead>
                                                        <tr>
                                                            <th>Descripcion</th>
                                                            <th>Medida</th>
                                                            <th>Cantidad</th>
                                                            <th>Precio</th>
                                                            <th>Monto</th>
                                                            <th>Acciones</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <tr>
                                                            <td colspan="6">
                                                                <h3 class="message-error" align="center"><b>No existen insumos agregados al detalle</b></h3>
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                    <tfoot>
                                                        <tr>
                                                            <td></td>
                                                            <td></td>
                                                            <td></td>
                                                            <td></td>
                                                            <td></td>
                                                            <td></td>
                                                        </tr>
                                                    </tfoot>
                                                </table>
                                            </EmptyDataTemplate>
                                            <LayoutTemplate>
                                                <table class="table table-hover table-condensed">
                                                    <thead>
                                                        <tr>
                                                            <th>Descripcion</th>
                                                            <th>Medida</th>
                                                            <th>Cantidad</th>
                                                            <th>Precio</th>
                                                            <th>Monto</th>
                                                            <th>Acciones</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <tr id="itemPlaceholder" runat="server" />
                                                    </tbody>
                                                    <tfoot>
                                                        <tr>
                                                            <td>
                                                                <%--<asp:Button runat="server"
                                                                    ID="btnActualizarDetalle"
                                                                    Text="Actualizar Detalle"
                                                                    CommandName="ActualizarDetalle" />--%>
                                                            </td>
                                                            <td></td>
                                                            <td></td>
                                                            <td>
                                                                <h3>Totall:</h3>
                                                            </td>
                                                            <td>
                                                                <h3>
                                                                    <asp:Label ID="lblTotal" runat="server"></asp:Label></h3>
                                                            </td>
                                                            <td></td>
                                                        </tr>
                                                    </tfoot>
                                                </table>
                                            </LayoutTemplate>
                                            <ItemTemplate>
                                                <tr>
                                                    <td><%# Eval("Insumo.DescripcionInsumo") %></td>
                                                    <td><%# Eval("Insumo.MedidaInsumo") %></td>

                                                    <td>
                                                        <asp:TextBox CssClass="form-control input-sm" runat="server" ID="txtCantidad" MaxLength="3" AutoPostBack="False" OnTextChanged="txtCantidad_TextChanged" Text='<%# Bind("Cantidad") %>' Width="60px" />
                                                        <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender6" TargetControlID="txtCantidad" FilterType="Numbers, Custom" ValidChars="." runat="server"></ajaxToolkit:FilteredTextBoxExtender>

                                                    </td>
                                                    <td>
                                                        <asp:TextBox CssClass="form-control input-sm" runat="server" AutoPostBack="False"  MaxLength="3" OnTextChanged="txtPrecio_TextChanged" ID="txtPrecio" Text='<%# Bind("PrecioUnit") %>' Width="60px" /></td>
                                                    <ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" TargetControlID="txtPrecio" FilterType="Numbers, Custom" ValidChars="." runat="server"></ajaxToolkit:FilteredTextBoxExtender>
                                                    <td><%# Eval("Monto") %></td>
                                                    <td>
                                                        <asp:Button ID="Button1" runat="server" Text="Quitar"
                                                            CssClass="btn btn-danger btn-sm"
                                                            CommandName="QuitarDetalle"
                                                            CommandArgument='<%# Eval("IdInsumo") %>' />
                                                    </td>
                                                </tr>
                                            </ItemTemplate>
                                        </asp:ListView>
                                    </ContentTemplate>
                                    <Triggers>
                                        <asp:AsyncPostBackTrigger ControlID="lvDetCompra" EventName="ItemCommand" />
                                        <asp:AsyncPostBackTrigger ControlID="lvInsumos" EventName="ItemCommand" />
                                    </Triggers>
                                </asp:UpdatePanel>
                            </div>


                        </div>
                    </div>

                </div>
                <%-- /col-lg-12 --%>
            </div>
            <%-- /boddy --%>
            <div class="panel-footer">
                <asp:Button runat="server" ID="btnGuardar" CssClass="btn btn-success" Text="Guardar" OnClick="btnGuardar_Click" />
                <asp:Button runat="server" ID="btnLimpiar" CssClass="btn btn-danger" Text="atrás" OnClick="btnCancelar_Click" OnClientClick="return confirm('Desea  salir a Listar Compras');" />

                <%--  <asp:Button ID="Button7" runat="server" Text="Cancelar" CssClass="btn btn-danger"/>--%>
            </div>
        </div>
    </div>

    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel"><strong>Cuotas de Pago</strong></h4>
                </div>
                <div class="modal-body">
                    <div class="row">
                        <div class="col-lg-4">
                            <h4>Nro. de cuotas:</h4>
                            <asp:TextBox ID="tbxCantidad" placeholder="Ejm: 2" CssClass="form-control input-sm" runat="server" />
                            <%--<asp:RequiredFieldValidator ID="rfvCantidad" runat="server" ControlToValidate="tbxCantidad" ErrorMessage=" Ingresa Cantidad" ForeColor="Red"></asp:RequiredFieldValidator>--%>
                        </div>
                        <div class="col-lg-4">
                            <h4>Rango de Fechas</h4>
                            <asp:DropDownList CssClass="form-control input-sm" ID="ddlFechPagos" runat="server">
                                <asp:ListItem Text="Semanal" />
                                <asp:ListItem Text="Quincenal" />
                                <asp:ListItem Text="Mensual" />
                            </asp:DropDownList>
                        </div>
                        <div class="col-lg-2">
                            <h4>Acciones</h4>
                            <asp:Button ID="btnAgregar" Text="Agregar" CssClass="btn btn-sm btn-info" runat="server" OnClick="btnAgregar_Click" />
                        </div>
                    </div>
                    <hr />

                    <asp:UpdatePanel ID="upCuotas" runat="server">
                        <ContentTemplate>
                                   <lu>
                                            <div class="col-md-4">
                                            <h4><strong>Monto</strong></h4>
                                            </div>
                                            <div class="col-md-4">
                                            <h4><strong>Fecha de Pago</strong></h4>
                                            </div>
                                            <div class="col-md-4">
                                            <h4><strong>Estado</strong></h4>
                                            </div>                                            
                                    </lu>
                            <br />
                            <br />
                            <%--Start ListView--%>
                            <asp:ListView ID="lvCuotas" runat="server"
                                ItemType="Box.Entities.PagoCompra">
                                <EmptyDataTemplate>
                                </EmptyDataTemplate>
                                <ItemTemplate>
                                    <ul class="list-group">
                                        <li class="list-group-item row">
                                            <div class="col-md-4">
                                                <asp:TextBox Enabled="False" ID="tbxMonto" Text="<%# Bind('MontoPagar') %>" CssClass="form-control input-sm" runat="server" />
                                            </div>
                                            <div class="col-md-4">
                                                
                                                <asp:TextBox Enabled="False" ID="tbxFechPago" Text="<%# Bind('FechaPagoCuota','{0:d}') %>" CssClass="form-control input-sm date" runat="server" />
                                            </div>
                                            <div class="col-md-4">
                                                
                                                <asp:TextBox Enabled="False" ID="tbxEstado" Text="<%# Bind('Estado') %>" CssClass="form-control input-sm date" runat="server" />
                                            </div>
                                        </li>
                                    </ul>
                                </ItemTemplate>
                            </asp:ListView>
                            <%--End ListView--%>
                        </ContentTemplate>
                        <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="btnAgregar" EventName="Click" />
                        </Triggers>
                    </asp:UpdatePanel>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
                </div>
            </div>
        </div>
    </div>

    <script src="../../Scripts/bootstrap.min.js"></script>
    <script>

            $(document).ready(function () {
                $(".btn btn-info btn-sm").click(function () {
                    var a = $('#MainContent_lvDetCompra_lblTotal').text();

                    $('#MainContent_tbxMonto1').val(a);
                });
            });

    </script>
</asp:Content>
